package com.tiancheng.trade.settlement.controller.admin;

import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.settlement.exception.BusinessException;
import com.tiancheng.trade.settlement.service.settlement.IPaymentBillQueryService;
import com.tiancheng.trade.settlement.service.settlement.IPaymentBillService;
import com.tiancheng.trade.settlement.vo.settlement.admin.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 流水对帐
 *
 * @author chris.shao
 * @since 2024-4-21
 */
@RestController
@RequestMapping("/admin/payment/bill")
public class PaymentBillAdminController {

    @Autowired
    private IPaymentBillQueryService paymentBillQueryService;
    @Autowired
    private IPaymentBillService paymentBillService;

    @GetMapping("/summary")
    public Result querySummaryView(PaymentBillQueryVO paymentBillQueryVO) throws BusinessException {
        return Result.success(paymentBillQueryService.querySummaryView(paymentBillQueryVO));
    }

    @GetMapping("/list")
    public Result queryItemList(PaymentBillDetailQuery paymentBillQueryVO) throws BusinessException {
        return Result.success(paymentBillQueryService.queryItemList(paymentBillQueryVO));
    }

    @GetMapping("/{id}")
    public Result queryItemDetail(@PathVariable Long id) throws BusinessException {
        return Result.success(paymentBillQueryService.queryItemDetail(id));
    }

    @PostMapping("/")
    public Result audit(@RequestBody List<PaymentBillHandleVO> list) throws BusinessException {
        return Result.success(paymentBillService.audit(list));
    }

    @PostMapping("/diffHandle")
    public Result diffHandle(@RequestBody @Valid List<PaymentDiffHandleVO> list) throws BusinessException {
        return Result.success(paymentBillService.diffHandle(list));
    }

    @GetMapping("/oldSystemDataListQuery")
    public Result queryOldSystemDataList(PaymentOldSystemQueryVO vo) throws BusinessException {
        return Result.success(paymentBillService.oldSystemDataListQuery(vo));
    }


    @PostMapping("/oldSystemDataHandle")
    public Result oldSystemDataHandle(@RequestBody @Valid PaymentOldSystemVO vo) throws BusinessException {
        return Result.success(paymentBillService.oldSystemDataHandle(vo));
    }

    @GetMapping("/querySubOrderByFlowId")
    public Result querySubOrderByFlowId(String flowId) throws BusinessException {
        return Result.success(paymentBillService.querySubOrderByFlowId(flowId));
    }

    /**
     * 流水明细对账导出
     *
     * @param paymentBillQueryVO
     * @return
     */
    @PostMapping("/export")
    public Result exportItemList(@RequestBody PaymentBillDetailQuery paymentBillQueryVO, HttpServletRequest request, HttpServletResponse response) throws IOException {
        paymentBillQueryService.export(paymentBillQueryVO, request, response);
        return Result.success("导出成功");
    }

}
